Repository navigation
fix(daily-cache): stop token-only slices inflating day totals on merge - #1788
Merged
Merged
Conversation
A slice with tokens but no calls, cost or savings (a Hermes or Copilot session total) read as a placeholder, so every adoption or re-derive merge replaced it while adding its tokens to the day and model rows again. Each version bump multiplied them by the number of older cache files holding the day. Count tokens as slice data, and cap day and model-row tokens at the slices' sum on load for days whose calls and cost match their slices, this bug's fingerprint, so caches already inflated heal without a version bump. A newer token-only slice now wins over an older one with calls, as the newer-wins rule intends, instead of the two being added.
iamtoruk
force-pushed
the
fix/daily-cache-token-inflation
branch
from
October 26, 2026 02:49
d5b22a3 to
abae3c2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Token totals on some days grow with every cache version bump.
A slice with tokens but no calls, cost or savings (a Hermes or Copilot session total) was treated as a placeholder. On every adoption or re-derive merge it was replaced while its tokens were added to the day and model rows again, so each bump multiplied them by the number of older cache files holding that day.
hasSliceDatacounts tokens as slice data.subtractSlicestill drops a token-only remainder, as before: it can be drift between two scans or usage whose source is gone, and nothing there tells which.A newer token-only slice now wins over an older one with calls, as the newer-wins rule intends, instead of the two being added.
Rebased on #1786 (cache v76). No version bump of its own. This must ship in the same release as #1786: the move to v76 adopts every older cache file a 0.9.27 user has, which is exactly the merge that inflated.
Tests: three new cases in
tests/daily-cache-carry-forward.test.ts; typecheck and the 39 suites that import the daily cache pass (548 tests).Real data on this Mac (isolated cache and config dirs, sources read-only):
Cost and calls are identical between main and this branch on every day in every scenario.